package package1;

import java.io.File;
import java.io.IOException;

public class TestForFolderPackSimple {
	/**
	 * pack current folder, skip jar file named with this folder
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		packCurrentFolder();
	}
	public String getName(){
		return this.getClass().getName();
	}
	private static void packCurrentFolder() throws IOException {
		String className = getCurrentClassName();
		String folderAddr = getCurrentFolder();
		File folder = new File(folderAddr);
		File[] files = folder.listFiles();
		StringBuffer sb = new StringBuffer();
		for(File f:files){
			//skip the jar named with the current java file
			if(f.getName().contains(className))
				continue;
			sb.append(f.getName()+" ");
		}
		System.err.println(sb.toString());
		String cmd;
//		cmd = "jar vcf 1.zip \""+folder.getAbsolutePath()+"\"";
		cmd = "jar vcf 1.zip "+sb.toString();
		run(cmd);
	}
	private static String getCurrentClassName() {
		String a =new Throwable().getStackTrace()[0].getClassName();
		a =a.substring(a.lastIndexOf(".")+1, a.length());
		return a;
	}
	
	private static String getCurrentFolder() {
		return System.getProperty("user.dir");
	}
	
	private static void run(String cmd) throws IOException {
		Runtime.getRuntime().exec(cmd);
	}

}
